import 'package:coincap/models/app_config.dart';
import 'package:dio/dio.dart';
import 'package:get_it/get_it.dart';

class HTTPService {
  final Dio dio = Dio();

  AppConfig? _appConfig;
  String? _base_url;

  HTTPService() {
    _appConfig = GetIt.instance.get<AppConfig>();
    _base_url = _appConfig!.COIN_API_BASE_URL;
    print(_base_url);
  }

  // Future<Response?> get(String _path) async {
  //   try {
  //     String _url = "$_base_url$_path";
  //     Response? _response = await dio.get(_url);
  //     print('HTTPService: $_response');
  //     return _response;
  //   } catch (e) {
  //     print('HTTPService: Unable to perform get request.');
  //     print(e);
  //   }
  // }

  Future<Response?> get(String _path) async {
    String data = "";
    if (_path == "/coins/bitcoin") {
      // ["market_data"]["current_price"]["usd"];
      // ["market_data"]["price_change_percentage_24h"]
      data = """
        {
          "market_data": { 
            "current_price": {"usd": 100}, 
            "price_change_percentage_24h": 0.01 
          },
          "description": {
            "en": "bitcoin description"
          },
          "image": "assets/images/flutter_coincap_10.png"
        }
      """;
    }
    if (_path == "/coins/ethereum") {
      data = """
        {
          "market_data": { 
            "current_price": {"usd": 200}, 
            "price_change_percentage_24h": 0.02
          },
          "description": {
            "en": "ethereum description"
          },
          "image": "assets/images/flutter_coincap_17.png"
        }
      """;
    }
    return Future.delayed(const Duration(seconds: 1), () {
      return Response(data: data, requestOptions: RequestOptions(path: ''));
    });
  }
}
